package com.oocl.products.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.products.service.ProductService;
import com.oocl.products.service.factory.ProductServiceFactory;

/**
 * Servlet implementation class ProductDeleteServlet
 */
public class ProductDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private ProductService productService;
 
    public ProductDeleteServlet() {
    	productService = ProductServiceFactory.getInstance();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String pid = request.getParameter("pid");
		String sid = request.getParameter("sid");
		if(productService.deleteProduct(pid)){
			response.sendRedirect("list?sid="+sid);
		}else{
			request.setAttribute("error", "delete error");
			request.getRequestDispatcher("../error.jsp").forward(request, response);
		}
	}


}
